/******************************************************************************/
//	DxImage.cpp	-	Loads graphics as D3D Textures
//
//	Author:		Russell Klinkerman
//	Created:	09.02.2004
//
/******************************************************************************/

#include "DxImage.h"

bool	CDxImage::Load(char *	szFile, D3DCOLOR dxColorKey)
{
	HRESULT hr = 0;

    if(pTexture)
		return false;	// Fail if there is an image already loaded.

	// Clear the image information struct.
	memset(&dxImageInfo, 0, sizeof(D3DXIMAGE_INFO));

	// Load the file
	hr = D3DXCreateTextureFromFileEx(	d3dManager.GetDevice(),	// D3D Device
										szFile,					// Image Filename
										D3DX_DEFAULT,			// Image Width (default = use file)
										D3DX_DEFAULT,			// Image Height (default = use file)
										D3DX_DEFAULT,			// # Miplevels (default = full chain)
										NULL,					// Usage (NULL = not RT/Dynamic)
										D3DFMT_UNKNOWN,			// Image Format (Unknown = use file)
										D3DPOOL_MANAGED,		// Memory Pool (Managed = kept on lost)
										D3DX_DEFAULT,			// Filter (Default = Triangle/Dither)
										D3DX_DEFAULT,			// Mip Filter (Default = Box)
										dxColorKey,				// Color Key
										&dxImageInfo,			// Image Info Structure
										NULL,					// Palette (NULL = not used)
										&pTexture				// Texture to receive image
									);

	// Make sure image loaded successfully
	if(FAILED(hr))
		return false;

	// Upon success...
	return true;
}

void	CDxImage::Unload()
{
	// Release the texture
	if(pTexture)
		pTexture->Release();

	pTexture = NULL;
}
